package com.dragon.gencode.conf.db;

import java.util.ArrayList;
import java.util.List;

public class DynamicDataSourceContextHolder {

	private static ThreadLocal<Object> CONTEXT_HOLDER = ThreadLocal.withInitial(() -> DataSourceKey.GEN.getName());
	
	public static List<Object> dataSourceKeys = new ArrayList<Object>();
	
	public static void setDataSourceKey(String key){
		CONTEXT_HOLDER.set(key);
	}
	
	public static Object getDataSourceKey(){
		return CONTEXT_HOLDER.get();
	}
	
	public static void clearDataSourceKey(){
		CONTEXT_HOLDER.remove();
	}
	
	public static Boolean containDataSourceKey(String key){
		return dataSourceKeys.contains(key);
	}

	public enum DataSourceKey {
		GEN("gen"),
		GEN_SQLITE("genSqlite"),
		GEN_CONF("genConf");

		private String name;

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		private DataSourceKey(String name) {
			this.name = name;
		}
	}
}